package com.laiyizhan.common.mapper;

import com.laiyizhan.common.model.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {
    @Delete({
            "delete from t_article",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_article (one_column_id, second_column_id, ",
            "title, author, banner, ",
            "icon, publish_date, ",
            "status, enable, ",
            "body)",
            "values (#{oneColumnId,jdbcType=INTEGER}, #{secondColumnId,jdbcType=INTEGER}, ",
            "#{title,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR}, #{banner,jdbcType=INTEGER}, ",
            "#{icon,jdbcType=VARCHAR}, #{publishDate,jdbcType=TIMESTAMP}, ",
            "#{status,jdbcType=INTEGER}, #{enable,jdbcType=INTEGER}, ",
            "#{body,jdbcType=LONGVARCHAR})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Article record);

    int insertSelective(Article record);

    @Select({
            "select",
            "id, one_column_id, second_column_id, title, author, banner, icon, publish_date, ",
            "status, enable, body",
            "from t_article",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("ResultMapWithBLOBs")
    Article selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Article record);

    @Update({
            "update t_article",
            "set one_column_id = #{oneColumnId,jdbcType=INTEGER},",
            "second_column_id = #{secondColumnId,jdbcType=INTEGER},",
            "title = #{title,jdbcType=VARCHAR},",
            "author = #{author,jdbcType=VARCHAR},",
            "banner = #{banner,jdbcType=INTEGER},",
            "icon = #{icon,jdbcType=VARCHAR},",
            "publish_date = #{publishDate,jdbcType=TIMESTAMP},",
            "status = #{status,jdbcType=INTEGER},",
            "enable = #{enable,jdbcType=INTEGER},",
            "body = #{body,jdbcType=LONGVARCHAR}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKeyWithBLOBs(Article record);

    @Update({
            "update t_article",
            "set one_column_id = #{oneColumnId,jdbcType=INTEGER},",
            "second_column_id = #{secondColumnId,jdbcType=INTEGER},",
            "title = #{title,jdbcType=VARCHAR},",
            "author = #{author,jdbcType=VARCHAR},",
            "banner = #{banner,jdbcType=INTEGER},",
            "icon = #{icon,jdbcType=VARCHAR},",
            "publish_date = #{publishDate,jdbcType=TIMESTAMP},",
            "status = #{status,jdbcType=INTEGER},",
            "enable = #{enable,jdbcType=INTEGER}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Article record);

    List<Article> list(@Param("status") Integer status,
                       @Param("title") String title,
                       @Param("oneColumnId") Integer oneColumnId,
                       @Param("secondColumnId") Integer secondColumnId);

    int countBanner();

    List<Article> listBanner();

}